package com.jlc.demo.controller;

import com.jlc.demo.beans.ResObject;
import com.jlc.demo.beans.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(description = "用户接口")
@RestController
@RequestMapping("/demoController")
public class DemoController {


    @ApiOperation(value = "新增用户", notes = "新增注册")
    @RequestMapping(value = "/createUser", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)

    public ResObject createUser(@RequestBody User user){
        System.out.println("createUser" + user.toString());
        return new ResObject(HttpStatus.OK.value(), "新增成功");
    }


    @ApiOperation(value = "修改用户", notes = "用户的修改")
    @RequestMapping(value = "/updateUser", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResObject updateUser(@RequestBody User user){
        System.out.println("createUser" + user.toString());
        return new ResObject(HttpStatus.OK.value(), "修改成功");
    }


    @ApiOperation(value = "删除用户", notes = "请把该用户删除掉")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户标识", required = true,paramType = "query",dataType = "String")
    })
    @RequestMapping(value = "/deleteUser", method = RequestMethod.DELETE)
    public ResObject deleteUser(@RequestParam("userId") String userId){
        System.out.println("userId" + userId);
        return new ResObject(HttpStatus.OK.value(), "删除成功");
    }


    @ApiOperation(value = "查询用户", notes = "查询出该用户")
    @RequestMapping(value = "/findUser", method = RequestMethod.GET)
    public ResObject findUser(@RequestParam("userId") String userId){
        System.out.println("userId" + userId);
        User user = new User(userId, "小可", "asd456", "88888@qq.com");
        return new ResObject(HttpStatus.OK.value(), user);
    }

}
